﻿Imports System.Data
Partial Class Empresas_RevPostulados_RevPostulados
    Inherits System.Web.UI.Page
    Dim NumCol As Integer = 10
    Dim NumCol2 As Integer = 8
    Private Function GetRecords() As DataTable
        Dim obj As New Ofertas
        Dim dt As DataTable = New DataTable
        dt = obj.GetxEmpresaPub(DropDownList1.SelectedValue)
        Return dt
    End Function
    Private Function GetbyOfertas() As DataTable
        Dim obj As New Ofertas
        Dim dt As DataTable = New DataTable
        dt = obj.GetbyOferta(GridView1.SelectedValue)
        Return dt
    End Function
    Public Sub LlenarGrid()
        Dim dtCustomer As DataTable = Me.GetRecords()
        GridView1.DataSource = dtCustomer
        GridView1.DataBind()
        If dtCustomer.Rows.Count < 1 Then
            dtCustomer.Rows.Clear()
            dtCustomer.Rows.Add(dtCustomer.NewRow())
            GridView1.DataSource = dtCustomer
            GridView1.DataBind()
            GridView1.Rows(0).Cells.Clear()
            GridView1.Rows(0).Cells.Add(New TableCell())
            GridView1.Rows(0).Cells(0).ColumnSpan = Me.NumCol
            GridView1.Rows(0).Cells(0).Text = "No hay registros"
        End If
    End Sub
    Public Sub LlenarGrid2()
        Dim dtCustomer As DataTable = Me.GetbyOfertas()
        GridView2.DataSource = dtCustomer
        GridView2.DataBind()
        If dtCustomer.Rows.Count < 1 Then
            dtCustomer.Rows.Clear()
            dtCustomer.Rows.Add(dtCustomer.NewRow())
            GridView1.DataSource = dtCustomer
            GridView1.DataBind()
            GridView1.Rows(0).Cells.Clear()
            GridView1.Rows(0).Cells.Add(New TableCell())
            GridView1.Rows(0).Cells(0).ColumnSpan = Me.NumCol
            GridView1.Rows(0).Cells(0).Text = "No hay postulados registrados para la oferta seleccionada"
        End If
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Me.LlenarGrid()
        End If
    End Sub
    Protected Sub DropDownList1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.DataBound
        LlenarGrid()
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        LlenarGrid()
    End Sub

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        Dim index As Integer = Convert.ToInt32(e.CommandArgument)
        Select Case e.CommandName
            Case "Postulados"
                GridView1.SelectedIndex = index
                LlenarGrid2()
                Me.MultiView1.ActiveViewIndex = 1
        End Select
    End Sub

    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Me.MultiView1.ActiveViewIndex = 0
    End Sub

    Protected Sub RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView2.RowEditing
        GridView2.EditIndex = e.NewEditIndex
        LlenarGrid2()
    End Sub
    Protected Sub RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView2.RowUpdating
        Dim obj As New Ofertas
        Dim CboEditLegalizado As DropDownList = DirectCast(GridView2.Rows(e.RowIndex).FindControl("CboEstado"), DropDownList)
        Dim txtprom As Telerik.Web.UI.RadNumericTextBox = DirectCast(GridView2.Rows(e.RowIndex).FindControl("TxtProm"), Telerik.Web.UI.RadNumericTextBox)
        Dim ofer As String = Me.GridView2.DataKeys(e.RowIndex).Values(0).ToString()
        Me.MsgModalPanel.Text = obj.Confirmar(CboEditLegalizado.SelectedValue, txtprom.Value, ofer)
        If obj.lErrorG = False Then
            ImgRst.ImageUrl = "~/imagenes/good.png"
        Else
            ImgRst.ImageUrl = "~/imagenes/error.png"
        End If
        Me.GridView2.EditIndex = -1
        LlenarGrid2()
        ModalPopup.Show()
    End Sub
    Protected Sub grd_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView2.RowCancelingEdit
        GridView2.EditIndex = -1
        LlenarGrid2()
    End Sub
End Class
